package com.info.zhiduoduo.common.excelconverter;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.info.zhiduoduo.common.utils.StringUtil;

/**
 *  项目是否需要自动验收 0:否 1:是
 */
public class AutoCheckConverter implements Converter<Integer> {

	@Override
	public Class supportJavaTypeKey() {
		return null;
	}

	@Override
	public CellDataTypeEnum supportExcelTypeKey() {
		return null;
	}

	@Override
	public Integer convertToJavaData(CellData cellData, ExcelContentProperty excelContentProperty,
	                                 com.alibaba.excel.metadata.GlobalConfiguration globalConfiguration) throws Exception {
		String value = cellData.getStringValue();
		if (StringUtil.equals(value, "否")) return 0;
		if (StringUtil.equals(value, "是")) return 1;
		return 0;
	}

	@Override
	public CellData convertToExcelData(Integer integer, ExcelContentProperty excelContentProperty,
	                                   com.alibaba.excel.metadata.GlobalConfiguration globalConfiguration) throws Exception {
		if (integer == null) {
			return new CellData("否");
		} else if (integer == 0) {
			return new CellData("否");
		} else if (integer == 1) {
			return new CellData("是");
		} else {
			return new CellData("否");
		}
	}
}
